package com.ming.server.dubbo.service;

import java.rmi.RemoteException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import com.ming.server.dubbo.model.PersonEntity;
import com.ming.server.dubbo.util.DBUtil;

public class DemoServerImpl implements DemoServer {
	
	public String sayHello(String str) {
		str = "Hello " + str + "  2:" + new Date();
		System.err.println("server:" + str);
		return str;
	}

	@Override
	public List<PersonEntity> GetList() {
		// TODO Auto-generated method stub
				System.out.println("Get Person Start!");
				List<PersonEntity> personList=new LinkedList();
				
				PersonEntity person1=new PersonEntity();
				person1.setAge(25);
				person1.setId(0);
				person1.setName("Leslie");
				personList.add(person1);
				
				PersonEntity person2=new PersonEntity();
				person2.setAge(25);
				person2.setId(1);
				person2.setName("Rose");
				personList.add(person2);
				
				return personList;
			}

	@Override
	public boolean checkLogin(String username, String password) throws RemoteException {

			DBUtil db = new DBUtil(
					"select * from user where username = ? and password = ? ");

			ResultSet rs = null;

			System.out.println(">>>>>>开始查询数据库<<<<<<");

			try {

				db.pst.setString(1, username);

				db.pst.setString(2, password);

				rs = db.pst.executeQuery();

				if (rs.next()) {

					System.out.println("用户名" + rs.getString("username") + "密码"
							+ rs.getString("password"));

					return true;

				}

				System.out.println(">>>>>>用户不存在<<<<<<");

			} catch (SQLException e) {

				e.printStackTrace();

			} finally {

				try {

					rs.close();

					db.close();

				} catch (SQLException e) {

					e.printStackTrace();

				}

			}

			return false;

		}
	}
